package com.ruoyi.web.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.otc.domain.OperationLog;
import com.ruoyi.otc.service.IOperationLogService;
import com.ruoyi.web.api.base.ApiBaseController;
import com.ruoyi.web.api.vo.OperationLogVo;
import com.ruoyi.web.constant.ApiConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Api(value = "日志管理接口",tags = "日志管理接口")
@RestController
@RequestMapping(ApiConstant.API_V1+"log")
public class ApiOperationLogController extends ApiBaseController {

    @Autowired
    private IOperationLogService operationLogService;


    /**
     * 查询操作日志列表
     */
    @ApiOperation("查询操作日志列表")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestBody OperationLogVo operationLog)
    {
        startPage();
        QueryWrapper<OperationLog> wrapper = new QueryWrapper<OperationLog>()
                .like(StringUtils.isNotBlank(operationLog.getUserName()), "user_name", operationLog.getUserName());
        if (operationLog.getStartTime() != null && operationLog.getEndTime() != null){
            Date startTime = new Date(operationLog.getStartTime());
            Date endTime = new Date(operationLog.getEndTime());
            wrapper.between("opt_time",startTime,endTime);
        }

        List<OperationLog> list = operationLogService.list(wrapper);
        return getDataTable(list);
    }
}
